/*
 * @Autor: mofish
 * @Date: 2022-08-25 10:17:26
 * @LastEditors: mofish
 * @LastEditTime: 2022-08-25 13:59:48
 * @Description: 安装依赖
 */
const spawn = require("cross-spawn");

const install = function ({ cwd, command }) {
  return new Promise((resolve, reject) => {
    const args = ["install"];
    const child = spawn(command, args, {
      cwd,
      stdio: ["pipe", process.stdout, process.stderr],
    });

    child.once("close", (code) => {
      if (code !== 0) {
        reject({
          command: `${command} ${args.join(" ")}`,
        });
        return;
      }
      resolve();
    });
    child.once("error", reject);
  });
};

module.exports = install;
